/**
 * Created with Vim7.3 Mac
 * @fileOverview : 
 * @author : Lyle lylechen2014@gmail.com
 * @since : 2016-08-19 11:11:52
 * @filename : /app/rn/peas_rn/src/common/menuUserInfo.js
 * @version : 
 * @description : 
 */


import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity
} from 'react-native';

let { width, height } = Utils.size;
import MyProfile from '../components/myProfile';
import NetWorkImg from '../common/networkImg';

class MenuUserInfo extends Component {

    constructor(props) {
        super(props);
        SceneObj.MenuUserInfo = this;
        Share.regResponder('photo','MenuUserInfo');
        this.state = {};
    }

    responseRender(type) {
        //console.log('MyProfileHead');
        this.forceUpdate();
    }

    render() {
        return (
        	    <View>
        	    <TouchableOpacity onPress={()=>this.myProfileGoto()} activeOpacity={1} >
	                <View style={styles.userNavHeader}>
	                    <NetWorkImg
	                        source={this.getPhoto()} 
	                        style={styles.userNavAvatar}
	                        loadSize={'small'}
	                    />
	                    <View style={styles.userNavUsername}>
	                        <Text style={styles.userNavUsernameTxt}>{this.getUsername()}</Text>
	                        {this.getGold()}
	                    </View>                                          
	                </View>
	                <Text style={styles.userNavHeadline}>
	                    {this.getHeadline()}
	                </Text>
	            </TouchableOpacity> 
	            </View> 
	    );
    }

    getPhoto() {
        let userObj = JSON.parse(Store.session_user_id);
        let img = userObj.pictures.length > 0 ? userObj.pictures[0].icon :null;
        return Share.defalutPhoto(userObj.account.gender,img);     
    }

    getUsername() {
        let userObj = JSON.parse(Store.session_user_id);
        return userObj.account.username;
    }

    getGold() {
        let userObj = JSON.parse(Store.session_user_id);
        let jsx = null;
        if(userObj.status.isGuest = 1){
            jsx = 
            <Image style={styles.userNavGoldIco} source={require('../img/gold_ico.png') } />
        }
        return (jsx);
    }

    getHeadline() {
        let userObj = JSON.parse(Store.session_user_id);
        return userObj.about.headline;
    }

    myProfileGoto() {
        this.props.that.switchMenu();
        let navigator  = this.props.getNav();
        Utils.navJumpTo(navigator, {
            name: 'MyProfile',
            component: MyProfile,
            title: 'MyProfile',
            navBarType: 1,
        }, 'left')
    }
}

const styles = StyleSheet.create({

    userNavHeader: {
      marginTop:17,
      height:45,
      flexDirection: 'row',
    },

    userNavAvatar: {
      width:45,
      height:45,
      marginLeft: 25,
      borderRadius:23,
    },

    userNavUsername: {
      marginLeft:10,
      height:45,
      justifyContent: 'center',
    },

    userNavHeadline: {
      marginTop:10,
      width:250,
      marginLeft:25,
      marginRight:25,
      color:'#5c5c5d',
      fontSize:12,
    },

    userNavUsernameTxt: {
      height:20,
      overflow:'hidden',
    },

    userNavGoldIco: {
      width:16,
      height:16,
      borderRadius:8,
    },
});

export default MenuUserInfo;

